import {getApplyUserPageList} from "@/api/contract/myContract.js";

export function flowInfoFunctions(prop, conId, nextFunction, loading, selectUserListRef, currentIsRefreshActivityNote) {
    const {proxy} = getCurrentInstance()
    const loadMainViewData = inject('loadMainViewData')

    watchEffect(() => {
        if (prop.isRefreshActivityNote) {
            setCurrentIsRefreshActivityNote(currentIsRefreshActivityNote)
        }
    })

    function refreshMainViewData() {
        loading.value = false
        loadMainViewData()
    }

    function handleApply() {
        selectUserListRef.value.openDialog()
    }

    function getApplyUserList(queryParams, callback) {
        getApplyUserPageList(queryParams).then(res => {
            callback(res)
        })
    }

    function handleSelectedUser(user) {
        loading.value = true
        const query = {id: conId, userId: user.id}
        nextFunction(query).then(() => {
            setCurrentIsRefreshActivityNote(currentIsRefreshActivityNote)
            proxy.$modal.msgSuccess("执行成功")
            refreshMainViewData()
        }).catch(() => {
            loading.value = false
        })
    }

    return {
        refreshMainViewData,
        handleApply,
        getApplyUserList,
        handleSelectedUser
    }
}

export function setCurrentIsRefreshActivityNote(currentIsRefreshActivityNote) {
    currentIsRefreshActivityNote.value = true
    setTimeout(() => {
        currentIsRefreshActivityNote.value = false
    }, 50)
}